package com.engr.lyx.blog.biz.service.impl;

import com.engr.lyx.blog.biz.enums.StatusEnum;
import com.engr.lyx.blog.biz.repository.tag.TagRepository;
import com.engr.lyx.blog.biz.service.TagService;
import com.engr.lyx.blog.client.entity.Tag;
import com.engr.lyx.common.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @program: blog
 * @description: tag
 * @author: lyx
 * @create: 2019-06-23
 **/
@Service
public class TagServiceImpl implements TagService {

    @Autowired
    private TagRepository tagRepository;

    @Override
    public List<Tag> selectTagsByUserId(Long userId) {

        return tagRepository.findAllByUserIdAndStatus(userId, StatusEnum.EFFECTIVE.getCode());
    }

    @Override
    public Tag selectTagById(long tagId) {

        return tagRepository.findByIdAndStatus(tagId, StatusEnum.EFFECTIVE.getCode()).
                orElseThrow(() -> new ServiceException("未查找到记录"));
    }

}
